#!/bin/bash
export HOMEDIR=$(dirname $(dirname $(readlink -f "${BASH_SOURCE[0]}")))
source $HOMEDIR/scripts/init-env.sh

p=""
echo 即将删除数据库 $ptk_global_biz_dbname ,输入 y 或 Y,回车继续安装，否则退出
read p
if [ "$p" == "Y" ] || [ "$p" == "y" ]; then
    echo "正在删除数据库"
else
    echo "用户操作退出"
    exit 1
fi

$OSEXEC gsql -c "clean connection to all force for database $ptk_global_biz_dbname";
$OSEXEC gsql -c "drop database $ptk_global_biz_dbname;"

drop_user_sql="
begin 
for rec in (select 'drop user '||usename||' cascade' cmd from pg_user where usesysid<>10) loop 
execute immediate rec.cmd; 
end loop; 
end; 
"
$OSEXEC gsql -c "$drop_user_sql"

source $HOMEDIR/scripts/create-database.sh

echo 已成功重建数据库 $ptk_global_biz_dbname